package com.msi;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

import com.msi.algorithm.CSPAlgorithm;
import com.msi.algorithm.Table;
import com.msi.gui.GUIAdapter;

/**
 * Klasa uruchamiająca algorytm obsadzania stołów
 * 
 * @author Michał Kołodziejski
 */
public class Main {

	static GUIAdapter gui;

	public static boolean ascendingSort = true;

	/**
	 * Uruchamia program
	 * 
	 * @param args
	 *            argumenty wywołania
	 */
	public static void main(String[] args) {

		boolean rootIsConfigured = Logger.getRootLogger().getAllAppenders()
				.hasMoreElements();
		if (!rootIsConfigured)
			BasicConfigurator.configure();
		gui = new GUIAdapter();

		javax.swing.SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				gui.createAndShowGUI();
			}
		});

		/*
		 * if(args.length != 2){ System.err.println(
		 * "Nieprawidłowe wywołanie generatora. Wymagane argumenty: n, r");
		 * System.exit(-1); }
		 * 
		 * int n = Integer.parseInt(args[0]); double r =
		 * Double.parseDouble(args[1]); Graph graph =
		 * GraphGenerator.generateGraph(n, r);
		 * 
		 * // instancja algorytmu i uruchomienie CSPAlgorithm cspAlgInstance =
		 * new CSPAlgorithm(graph); Thread algorithmThread = new
		 * Thread(cspAlgInstance); algorithmThread.start();
		 * 
		 * while(!cspAlgInstance.isAlgorithmFinished()){ try {
		 * Thread.sleep(1000);
		 * 
		 * } catch (InterruptedException e) {
		 * System.err.println("InterruptedException"); System.exit(-1); } }
		 * 
		 * List<Table> tables = cspAlgInstance.getResult();
		 * 
		 * // wypisanie wyników System.out.println(); for(int i=1;
		 * i<=tables.size(); ++i){ List<Vertex> guests =
		 * tables.get(i-1).getListOfSittingGuests(); StringBuffer sb = new
		 * StringBuffer(); sb.append("Table "); sb.append(i); sb.append(":");
		 * for(Vertex guest : guests){ sb.append(" "); sb.append(guest.getId());
		 * } System.out.println(sb.toString()); }
		 */
	}

	@SuppressWarnings("unused")
	private static Graph getTestGraph() {
		List<List<Integer>> matrix = new ArrayList<List<Integer>>();

		// v0
		List<Integer> v0list = new ArrayList<Integer>();
		v0list.add(0);
		v0list.add(1);
		v0list.add(1);
		v0list.add(1);

		// v1
		List<Integer> v1list = new ArrayList<Integer>();
		v1list.add(1);
		v1list.add(0);
		v1list.add(1);
		v1list.add(0);

		// v2
		List<Integer> v2list = new ArrayList<Integer>();
		v2list.add(1);
		v2list.add(1);
		v2list.add(0);
		v2list.add(0);

		// v3
		List<Integer> v3list = new ArrayList<Integer>();
		v3list.add(1);
		v3list.add(0);
		v3list.add(0);
		v3list.add(0);

		// matrix
		matrix.add(v0list);
		matrix.add(v1list);
		matrix.add(v2list);
		matrix.add(v3list);

		Graph g = Graph.createGraphByNeighbourMatrix(matrix);
		return g;
	}
}
